package com.tmsps.ne4Weixin.api;

import com.alibaba.fastjson.JSONObject;
import com.tmsps.ne4Weixin.beans.ShortUrl;
import com.tmsps.ne4Weixin.config.WxConfig;
import com.tmsps.ne4Weixin.utils.HttpClient;

/**
 * 
 * @author zhangwei 396033084@qq.com ShortUrlAPI 短地址url
 */
public class ShortUrlAPI extends BaseAPI {
	
	private final String requestUrl = BaseURL.concat("/cgi-bin/shorturl?access_token=%s");
			

	public ShortUrlAPI(WxConfig config) {
		super(config);
	}
	
	public ShortUrl getShortUrl(String longUrl){
		JSONObject jo = new JSONObject();
		jo.put("action", "long2short");
		jo.put("long_url", longUrl);
		String result = HttpClient.postJson(String.format(requestUrl, config.getAccessToken()), jo.toJSONString());
		return JSONObject.parseObject(result, ShortUrl.class);
	}
}
